/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.model.pcds;

import br.gov.cemaden.library.model.Usuario;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.Size;

/**
 *
 * @author paulo.dias
 */
@Entity
@Table(name = "pcds_rede", schema = "pcds")
@SequenceGenerator(name = "sequence", sequenceName = "pcds.pcds_rede_sequence", schema = "pcds")
@NamedQueries({
    @NamedQuery(name = "Rede.findAll", query = "SELECT p FROM Rede p ORDER BY p.idRede"),
    @NamedQuery(name = "Rede.findByIdRede", query = "SELECT p FROM Rede p WHERE p.idRede = :idRede"),
    @NamedQuery(name = "Rede.findByNome", query = "SELECT p FROM Rede p WHERE p.nome = :nome"),
    @NamedQuery(name = "Rede.findBySigla", query = "SELECT p FROM Rede p WHERE p.sigla = :sigla"),
    @NamedQuery(name = "Rede.findByPercMinFuncto", query = "SELECT p FROM Rede p WHERE p.percMinFuncto = :percMinFuncto"),
    @NamedQuery(name = "Rede.findByTempoMaxSemAquisicao", query = "SELECT p FROM Rede p WHERE p.tempoMaxSemAquisicao = :tempoMaxSemAquisicao")})
public class Rede implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
    @Column(name="id_rede", nullable = false, unique = true)    
    private Long idRede;
    @Size(max = 255)
    @Column(name = "nome")
    private String nome;
    @Size(max = 255)
    @Column(name = "sigla")
    private String sigla;
    @Column(name = "perc_min_functo")
    private Short percMinFuncto;
    @Column(name = "tempo_max_sem_aquisicao")
    private Integer tempoMaxSemAquisicao;
    
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "smp_usuario_rede", schema = "smp", 
            joinColumns = {@JoinColumn(name = "id_rede")},
            inverseJoinColumns = {@JoinColumn(name = "id_usuario")})
    private Set<Usuario> usuarios = new HashSet<Usuario>();

    public Rede() {
    }

    public Rede(Long idRede) {
        this.idRede = idRede;
    }

    public Long getIdRede() {
        return idRede;
    }

    public void setIdRede(Long idRede) {
        this.idRede = idRede;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getSigla() {
        return sigla;
    }

    public void setSigla(String sigla) {
        this.sigla = sigla;
    }

    public Short getPercMinFuncto() {
        return percMinFuncto;
    }

    public void setPercMinFuncto(Short percMinFuncto) {
        this.percMinFuncto = percMinFuncto;
    }

    public Integer getTempoMaxSemAquisicao() {
        return tempoMaxSemAquisicao;
    }

    public void setTempoMaxSemAquisicao(Integer tempoMaxSemAquisicao) {
        this.tempoMaxSemAquisicao = tempoMaxSemAquisicao;
    }
    
    public Set<Usuario> getUsuarios() {
        return usuarios;
    }

    public void setUsuarios(Set<Usuario> usuarios) {
        this.usuarios = usuarios;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idRede != null ? idRede.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rede)) {
            return false;
        }
        Rede other = (Rede) object;
        if ((this.idRede == null && other.idRede != null) || (this.idRede != null && !this.idRede.equals(other.idRede))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Rede{" + "idRede=" + idRede + ", nome=" + nome + ", sigla=" + sigla + ", percMinFuncto=" + percMinFuncto + ", tempoMaxSemAquisicao=" + tempoMaxSemAquisicao + '}';
    }    
    
}
